package io.renren.modules.creditWarning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.creditWarning.dao.UserCreditDao;
import io.renren.modules.creditWarning.dto.UserCreditDTO;
import io.renren.modules.creditWarning.entity.UserCreditEntity;
import io.renren.modules.creditWarning.service.UserCreditService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 用户学分表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2024-05-12
 */
@Service
public class UserCreditServiceImpl extends CrudServiceImpl<UserCreditDao, UserCreditEntity, UserCreditDTO> implements UserCreditService {

    @Override
    public QueryWrapper<UserCreditEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<UserCreditEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public UserCreditDTO getByUserId(Long userId) {
        QueryWrapper<UserCreditEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        UserCreditEntity entity = this.baseDao.selectOne(wrapper);
        return ConvertUtils.sourceToTarget(entity, UserCreditDTO.class);
    }
}